$(function(){
	
	$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
	
	$("#login-button").click(function(){
		showDiv('login-div','no-login-div');
	});
	$("#register-button").click(function(){
		showDiv('register-div','no-login-div');
	});
	$("#go-to-register").click(function(){
		showDiv('register-div','login-div');
	});
	$("#go-to-login").click(function(){
		showDiv('login-div','register-div');
	});
	$("#personal").click(function(){
		$("#enterprise .register-checked").hide();
		if($("#enterprise").hasClass('active')){
			$("#enterprise").removeClass('active');
		}
		$(this).addClass('active');
		$("#personal .register-checked").show();
		$('input[name=user_type]').val(0);
	});
	$("#enterprise").click(function(){
		if($("#personal").hasClass('active')){
			$("#personal").removeClass('active');
		}
		$("#personal .register-checked").hide();
		$(this).addClass('active');
		$("#enterprise .register-checked").show();
		$('input[name=user_type]').val(1);
	});
    //注册表单回车监听事件
    $('#register-form').keydown(function(e){
        var e = e || event,
            keycode = e.which || e.keyCode || e.charCode;
        if (keycode==13) {
            commonregister();
        }
    });
    $("#register-action").click(function(){
            commonregister();
    });
    //登陆表单回车监听事件
    $('#login-form').keydown(function(e){
        var e = e || event,
            keycode = e.which || e.keyCode || e.charCode;
        if (keycode==13) {
            indexlogin();
        }
    });
	$("#login-action").click(function(){
           indexlogin();
	});
    $('#login-form-new').keydown(function(e){
        var e = e || event,
            keycode = e.which || e.keyCode || e.charCode;
        if (keycode==13) {
            commonlogin();
        }
    });
    $("#login-action-new").click(function(){
           commonlogin();
    });
    $('#addmorenotice').click(function(){
    	var i = getRandom('notice');
    	var html="<div class='form-group can-del clearfix'><div class='col-xs-12 col-sm-3 col-3 ft-16 cor-2'></div><div class='col-sm-9 col-xs-12'>"+
                "<input class='form-control' name='notice[]' placeholder='注意事项'>"
                +"</div><a class=\"delete-btn\"  onclick=\"deleteStep(this)\"><i class=\"icon-remove\"></i></a>"
                +"</div>";
    	$('#notices').append(html);
    });
    $('#addmoretools').click(function(){
        var i = getRandom('tools');
    	var html="<div class='form-group can-del clearfix'><div class='col-xs-12 col-sm-3 col-3 ft-16 cor-2'></div><div class='col-sm-9 col-xs-12'>"
                +"<input type='text' class='form-control' name='tools[]' placeholder='工具/原料'>"
                +"</div><a class=\"delete-btn\"  onclick=\"deleteStep(this)\"><i class=\"icon-remove\"></i></a>"
            +"</div>";
    	$('#tools').append(html);
    });
    $('#addmorecontent').click(function(){
    	addMoreContent("content_step_1");
    });
    $("#addnewcontent").click(function(){
    	var i = getRandom('content_title');
    	var html = '<div id="content_step_'+i+'">'
				   +' 	<div class="form-group can-del clearfix" >'
				   +'       <div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2">'
				   +'           <input type="text" class="form-control" name="content_title_'+i+'" value="方法／步骤">'
				   +'       </div>'
				   +'       <div class="col-sm-9 col-xs-12">'
				   +'           <textarea class="form-control content" name="content_step_'+i+'_'+i+'"></textarea>'
				   +'           <div class="dropzone clearfix" id="content_step_'+i+'_'+i+'_img_box"><span class="text-left">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>'
				   +'       </div>'
				   +'		<a class=\"delete-btn\"  onclick=\"deleteBigStep(this)\"><i class=\"icon-remove\"></i></a>'
				   +'   </div>'
				   +'</div>';
    	html += '<div class="form-group clearfix"><div class="col-xs-12 col-sm-3 col-3 ft-16 cor-2"></div>'
			+'	<div class="col-sm-3">'
			+'        <button type="button" class="btn btn-default btn-block" name="addmorecontent" onclick="addMoreContent(\'content_step_'+i+'\')" ><i class="glyphicon glyphicon-plus"></i>添加方法/步骤</button>'
			+'    </div>'
			+'</div>';
    	$("#content-layout").append(html);
    	editorInit();
    	xweidrag();
    });
    $(".has-more").mouseover(function(){
    	$(this).find('.icon-img').css({'z-index':'11'});
    	$(this).find('img').addClass('animotion-img');
		$(this).find('.to-more-infomation').css({'display':"block","background":"#f6f6f6"});
	});
    $(".has-more").mouseleave(function(){
    	$(this).find('.icon-img').css({'z-index':'0'});
    	$(this).find('img').removeClass('animotion-img');
		$(this).find('.to-more-infomation').css({'display':"none","background":"#fff"});
	});

    $("#show-weibo-img").hover( function(event){
        $("#weibo-img").show();
    }, function(event){
        $("#weibo-img").hide();
    } );

    $("#show-weixin-img").hover( function(event){
        $("#weixin-img").show();
    }, function(event){
        $("#weixin-img").hide();
    } );
	$('#jump_next').click(function(){
		var phone = $('#register-form input[name=username]').val();
		var token = $('#register-form input[name=_token]').val();
		var verify_code = $('#register-form input[name=verify_code]').val();
		var phone_code = $('#register-form input[name=phone_code]').val();
		$.post('/checkcode',{'phone':phone,'_token':token,'verify_code':verify_code,'phone_code':phone_code},function(data){
			if(data.status=='success'){
				$('#step_1').hide();
				$('#step_2').show();
			}else{
				layer.msg(data.msg,{time:1000});
			}
		});
	});
	$(document).on('click','.join_cimo',function(){
		var params = {
				url: '/checklogin',
				type: 'GET',
				dataType: 'json',
				data: {},
		};
		$.ajax(params).done(function(data){
			if(data.status == 'success') {
				var url = '/member/resume/create';
				window.location.href=url;
			} else {
				ShowLogin('MyDiv','fade');
			}
		}).fail(function(){
			ShowLogin('MyDiv','fade');
		});
	});
});
//注册事件
function commonregister(){
        var data = $("#register-form").serialize();
        var username = $('#register-form input[name=username]').val();
        var pwd = $('#register-form input[name=password]').val();
        var repwd = $('#register-form input[name=repassword]').val();
        var search_str = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        var reg = /^1[3|4|5|7|8]\d{9}$/;
        if(!search_str.test(username) && !reg.test(username)){
            if($(".error-div").has('hide'))
                $(".error-div").removeClass('hide');
            layer.msg('邮箱或手机号格式不对！请检查后重新输入！',{time: 1000});
            return false;
        }
        if(pwd == '' || repwd == ''){
        	layer.msg('密码不可为空',{time: 1000});
        	return false;
        }
        if(pwd.length<6 || pwd.length > 15){
        	layer.msg('密码长度不可小于6或大于15',{time: 1000});
        	return false;
        }
        if(pwd != repwd)
        {
        	layer.msg('密码不可为空',{time: 1000});
        	return false;
        }
        if($('input[name=is_remember]').is(':checked') == false)
        {
            if($(".error-div").has('hide'))
                $(".error-div").removeClass('hide');
            layer.msg('请先阅读青苜用户协议，谢谢！',{time: 1000});
            return false;
        }
        $.ajax({
            'url':'/register',
            'type':'POST',
            'data':data,
            error: function(data) {
                var response = data.responseJSON;
                $.each(response,function(k,v){
                    errors +="<div>"+v+"</div>";
                })
                layer.open({
                    title: '系统提示',
                    content: errors
                });
            },
            success: function(data){
                if(data.status == 'success'){
//                    showDiv('login-div','register-div');
                	layer.msg(data.msg,{time: 1000},function(){
                    	window.location.reload();
                    });
                }else{
//                    if($(".error-div").has('hide'))
//                        $(".error-div").removeClass('hide');
//                    $(".error-div").html(data.msg)
                	layer.msg(data.msg,{time: 1000});
                }

            }
        });
}
//首页登陆事件
function indexlogin(){
    var data = $("#login-form").serialize();
    $.ajax({
        'url':'/login',
        'type':'POST',
        'data':data,
        error: function(data) {
            var response = data.responseJSON;
            $.each(response,function(k,v){
                errors +="<div>"+v+"</div>";
            })
            layer.open({
                title: '系统提示',
                content: errors
            });
        },
        success: function(data){
            if(data.status == 'success'){
                loginSuccess(data.data.group_id);
            }else{
                layer.open({
                    title: '系统提示',
                    content: data.msg
                });
            }

        }
    });
}
function loginSuccess(group_id)
{
	showDiv('no-login-div','login-div');
    var html = '<ul class="dropdown-menu-user">';
    if(group_id == 2){
        $("#login-on").html("<a href='/company/center'>［ 进入企业中心 ］</a>");
        html+='<li><a href="/biz"><i class="icon-user"></i>&nbsp;&nbsp;工作中心</a></li>'
            +'<li class="bodertop"><a href="/biz/talent"><i class="icon-folder-close"></i>&nbsp;&nbsp;人才匹配</a></li>'
            +'<li class="bodertop"><a href="/biz/cominf-index"><i class="icon-upload-alt"></i>&nbsp;&nbsp;企业风采</a></li>'
            +'<li class="bodertop"><a href="/company/center/message"><i class="icon-envelope-alt"></i>&nbsp;&nbsp;私信</a></li>'
            +'<li class="bodertop"><a href="/logout"><i class="icon-off"></i>&nbsp;&nbsp;退出</a></li>'
            +'</ul>';
    }else if(group_id == 3){
        $("#login-on").html("<a href='/member/index'>［ 进入个人中心 ］</a>");
        html+='<li><a href="/member/resume"><i class="icon-user"></i>&nbsp;&nbsp;我的简历</a></li>'
            +'<li class="bodertop"><a href="/member/delivery"><i class="icon-folder-close"></i>&nbsp;&nbsp;我的工作</a></li>'
            +'<li class="bodertop"><a href="/member/index"><i class="icon-upload-alt"></i>&nbsp;&nbsp;我的上传</a></li>'
            +'<li class="bodertop"><a href="/member/comments"><i class="icon-comments"></i>&nbsp;&nbsp;我的评论</a></li>'
            +'<li class="bodertop"><a href="/member/message"><i class="icon-envelope-alt"></i>&nbsp;&nbsp;我的私信</a></li>'
            +'<li class="bodertop"><a href="/member/account"><i class="icon-cogs"></i>&nbsp;&nbsp;我的账户</a></li>'
            +'<li class="bodertop"><a href="/logout"><i class="icon-off"></i>&nbsp;&nbsp;退出</a></li>'
            +'</ul>';
    }else if(group_id == 1){
        $("#login-on").html("<a href='/admin/index'>［ 进入后台管理 ］</a>");
        html+='<li><a href="/member/resume"><i class="icon-user"></i>&nbsp;&nbsp;我的简历</a></li>'
            +'<li class="bodertop"><a href="/member/delivery"><i class="icon-folder-close"></i>&nbsp;&nbsp;我的工作</a></li>'
            +'<li class="bodertop"><a href="/member/index"><i class="icon-upload-alt"></i>&nbsp;&nbsp;我的上传</a></li>'
            +'<li class="bodertop"><a href="/member/comments"><i class="icon-comments"></i>&nbsp;&nbsp;我的评论</a></li>'
            +'<li class="bodertop"><a href="/member/message"><i class="icon-envelope-alt"></i>&nbsp;&nbsp;我的私信</a></li>'
            +'<li class="bodertop"><a href="/member/account"><i class="icon-cogs"></i>&nbsp;&nbsp;我的账户</a></li>'
            +'<li class="bodertop"><a href="/admin/index"><i class="icon-cogs"></i>&nbsp;&nbsp;后台管理</a></li>'
            +'<li class="bodertop"><a href="/logout"><i class="icon-off"></i>&nbsp;&nbsp;退出</a></li>'
            +'</ul>';
    }
    $("#login-on").show();
    $("#no-login").hide();
    $(".header-user").append(html);
}
//公共登陆事件
function commonlogin(){
    var data = $("#login-form-new").serialize();
    $.ajax({
        'url':'/login',
        'type':'POST',
        'data':data,
        error: function(data) {
            var response = data.responseJSON;
            $.each(response,function(k,v){
                errors +="<div>"+v+"</div>";
            })
            layer.open({
                title: '系统提示',
                content: errors
            });
        },
        success: function(data){
            if(data.status == 'success'){
                CloseLogin('MyDiv','fade');
                if(data.data.group_id == 2){
                    layer.msg('恭喜您，登录成功！', {time: 1}, function () {
                		window.location.href="/biz/cominfo-index";
                    });
                }else{
                    layer.msg('恭喜您，登录成功！', {time: 1}, function () {
                            window.location.reload();
                	});
                }
            }else{
                layer.open({
                    title: '系统提示',
                    content: data.msg
                });
            }

        }
    });
}
/**
 * 修改步骤名称
 * @param own
 * @param id
 */
function contentTitleEdit(own,id)
{
	$(own).parent().hide();
	$("#"+id).show();
}
/**
 * 添加小步骤
 * @param id
 */
function addMoreContent(id){
	var i = getRandom(id);
	var hm = id+'_'+i;
	var html="<div class='form-group can-del clearfix'>"
				+"<div class='col-xs-12 col-sm-3 col-3 ft-16 cor-2'></div>"
				+"<div class='col-sm-9 col-sm-12'>"
					+"<textarea class='form-control content' name='"+hm+"'></textarea>"
					+" <div class='dropzone clearfix' id='"+hm+"_img_box'><span class=\"text-left\">&nbsp;&nbsp;&nbsp;请将右侧图片库的图片移入此处</span></div>"
				+"</div>"
				+"<a class=\"delete-btn\"  onclick=\"deleteStep(this)\"><i class=\"icon-remove\"></i></a>"
			+"</div>";
	$('#'+id).append(html);
	editorInit();
	xweidrag();
}
/**
 * 编辑器初始化
 */
function editorInit()
{
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('.content', {
	    	resizeType : 1,
	    	//allowPreviewEmoticons : false,
	    	afterBlur: function () { this.sync(); },
	    	allowImageUpload : true,
	    	width : "100%",
	    	allowUpload : true,
	    	//postParams:123,
	    	//uploadJson : '/index.php?g=User&m=Upyun&a=kindedtiropic',
	    	items : ["justifyleft", "justifycenter", "justifyright" ]
		});

	});
}

function bbseditorInit()
{
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('#comment-reply-content1', {
            resizeType : 1,
            //allowPreviewEmoticons : false,
            afterBlur: function () { this.sync(); },
            allowImageUpload : true,
            width : "100%",
            allowUpload : true,
            //postParams:123,
            //uploadJson : '/index.php?g=User&m=Upyun&a=kindedtiropic',
            items : []
        });

    });
}
/**
 * 删除步骤
 */
function deleteStep(id)
{
	$(id).parent().remove();
}
function deleteImg(id)
{
	$(id).remove();
}
/**
 * 删除大步骤
 */
function deleteBigStep(id){
	$(id).parent().parent().next().remove();
	$(id).parent().parent().remove();
}
/**
 * 获取碎挤汁
 * @param tree
 */
function getRandom(tree){
	var i = Math.floor(Math.random()*(100-10+1)+10);
	if($("#"+tree+"_"+i).length > 0){
		i = getRandom(tree);
	}
	return i;
}
/**
 * 旋转切换
 * @param toshow  展示的div
 * @param tohide  隐藏的div
 */
function showDiv(toshow,tohide){
	if($("#"+toshow).hasClass('no-login-div-turn-over')){
		$("#"+toshow).removeClass('no-login-div-turn-over');
	}
	$("#"+toshow).addClass('login-div-turn-over');
	$("#"+tohide).addClass('no-login-div-turn-over');
}

//弹出登陆层
function ShowLogin(show_div,bg_div){
    document.getElementById(show_div).style.display='block';
    document.getElementById(bg_div).style.display='block' ;
    var bgdiv = document.getElementById(bg_div);
    bgdiv.style.width = document.body.scrollWidth;
    $("#"+bg_div).height($(document).height());
}

//关闭登陆层
function CloseLogin(show_div,bg_div)
{

    try {
        document.getElementById(show_div).style.display = 'none';
        document.getElementById(bg_div).style.display = 'none';
    }
    catch (err) {

    }

}

//提示登录
function  loginTips()
{
	layer.msg('请登陆先...',{time:1000});
	ShowLogin('MyDiv','fade');
}
function tologin() {
    var prev = encodeURIComponent(window.location.pathname);
    layer.msg('请登陆先...', {time: 1000});
    window.location.href = '/guestlogin?rurl='+prev;
}

//个人中心跳转
function  MemberUrl()
{
    var url = "/member/index";
    window.location.href = url;
}

//发布需求跳转
function  NeedUrl()
{
    var url = "/member/resume/create";
    window.location.href = url;
}

function  ANeedUrl()
{
    layer.msg("您还没有简历，请先创建简历");
    var url = "/member/resume/resume-create";
    window.location.href = url;
}

//企业中心跳转
function  CompanyUrl()
{
    var url = "/biz/cominfo-index";
    window.location.href = url;
}

function  camjoin()
{
    var kid=0;
        $.ajax({
            'url': '/campusmember/resume/notify-list?kid=' + kid,
            'type': 'GET',
            error: function (data) {
                layer.open({title: '系统提示', content: '您还没有简历'});
            },
            success: function (response) {
                var result = response.data;
                var examlist_html = '<input type="hidden" id="camrid" value="'+kid+'">';
                //examlist_html += '<option value="0">选择简历</option>';
                if (response.data != '1') {
                    examlist_html += '<select style="width:90px; height:29px;" name="examlist" id="examlist">';
                    $.each(result, function (key, exp) {
                        examlist_html += ' <option value="' + key + '">' + exp + '</option>';
                    })
                    examlist_html += '</select>'
                        + '<button style="width:90px; height:30px; margin-left: 10px;" type="submmit" class="camresumesel">确认</button>';
                    examlist_html += '<p style="margin-top: 26px;"><a href="/campusmember/resume/resume-add">点此创建简历</a></p>';
                } else {
                    //examlist_html += '</select>';
                    examlist_html += '<div class="no_exam">抱歉，没有简历<a href="/campusmember/resume/resume-add">点此创建简历</a></div>';
                }
                //alert(examlist_html);
                $('#examSelect').html(examlist_html);
                $('#examModal').modal();
            }
        });

}

$(document).on('click', '.camresumesel', function () {
    var kid = $("#examlist").val();
    //var des = $("#examlist").val();
    $('#examModal').modal('hide');
    $.ajax({
        'url': '/campusmember/resume/resume-select?kid=' + kid,
        'type': 'GET',
        error: function (data) {
            layer.open({title: '系统提示', content: '该岗位还没有试卷'});
        },
        success: function (response) {

            if (response.data) {
                layer.msg("加入成功");
            } else {
                layer.msg("加入失败");
            }
            //alert(examlist_html);

        }
    });
});

function  campub()
{
    var url = "/campusenterprise/camjobadd";
    window.location.href = url;
}

//微博连接跳转
function  WeiBoUrl()
{
    var url = "http://weibo.com/u/5603350336";
    window.location.href = url;
}

/**
 * 用户收藏
 */
function toCollect(url,app,appid,token,uid)
{
	if(uid>0){
		$.ajax({
			'url':url,
			'type':'POST',
			'data':"_token="+token+"&app="+app+"&appid="+appid,
			error: function(data) {
				var response = data.responseJSON;
				$.each(response,function(k,v){
					errors +="<div>"+v+"</div>";
                });
				layer.open({
					title: '系统提示',
                    content: errors
                });
				//BootstrapDialog.alert({title:'错误提示',message:errors});
	        },
			success: function(data){
				if(data.status == 'success'){
                                        var path = window.location.pathname;
					var num = parseInt($("#collect_num span").text())+1;
					var html ="";
					if(app == 'teaches'){
                                                 if(path=="/teaches/list/1/"|| path=="/teaches/list/1") {
                            var tname = "#"+"collect_num" + appid;
                            var numt = parseInt($("#"+"collect_num"+appid+" span").text())+1;
                            html = '<img style="width:14px; padding-bottom: 3px;" class="ml-20" src="/images/front/jiuyezhinan/red-heart.png" title="收藏">'
                                + '<span style="margin-left: 5px;" class="color-gray">' + numt + '</span>';
                            $(tname).html(html);
                        }
						html = '<img style="width:14px; padding-bottom: 3px;" class="" src="/images/front/jiuyezhinan/red-heart.png" title="收藏">';
                    }
                   else if (app == 'teaches_content') {
                        html = "已收藏";
                    } else {
                        if (path == "/employ/list/" || path == "/employ/list") {
                            var iname = "#"+"collect_num" + appid;
                            var numu = parseInt($("#"+"collect_num"+appid+" span").text())+1;
                            html = '<img class="ml-20" src="/images/front/jiuyezhinan/red-heart.png" title="收藏">'
                                +'<span class="color-orange">'+numu+'</span>';
                            $(iname).html(html);
                        }
						html = '<img src="/images/front/jiuyezhinan/red-heart.png" title="收藏">&nbsp;&nbsp;'
                            + '<span class="color-orange">' + num + '</span>';
					}
					$("#collect_num").html(html);

                } else {
					layer.msg(data.msg, {icon: 1});
				}
			},
		});
	}else{
		layer.msg('请登陆先...',{time:1000});
		ShowLogin('MyDiv','fade');
	}
}
/**
 * 点赞
 */
function toApprove(url,app,appid,token)
{
	$.ajax({
		'url':url,
		'type':'POST',
		'data':"_token="+token+"&app="+app+"&appid="+appid,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({
				title: '系统提示',
                content: errors
            });
        },
		success: function(data){
			if(data.status == 'success'){
				var num = parseInt($("#nice-point-count").text())+1;
				$("#nice-point-count").html(num);
			}else{
				layer.open({
					title: '系统提示',
                    content: data.msg
                });
			}
		},
	});
}
/**
 * 图片上传
 * @param elm
 * @param opts
 * @param options
 */
function showImageDialog(elm, opts,options) {
	require(["util"], function(util){
		var btn = $(elm);
		var ipt = btn.parent().prev();
		var val = ipt.val();
		var img = ipt.parent().next().children();
		var thumb = $("#thumb");
		util.image(val, function(url){
			if(url.url){
				if(img.length > 0){
					img.get(0).src = url.url;
				}
				ipt.val(url.filename);
				ipt.attr("filename",url.filename);
				ipt.attr("url",url.url);
				if(thumb)
					thumb.val(url.attachment_id);
			}
			if(url.media_id){
				if(img.length > 0){
					img.get(0).src = "";
				}
				ipt.val(url.media_id);
			}
		},opts, options);
	});
}
/**
 * 删除图片
 * @param elm
 */
function deleteImage(elm){
	require(["jquery"], function($){
		$(elm).prev().attr("src", "/images/nopic.jpg");
		$(elm).parent().prev().find("input").val("");
		var thumb = $("#thumb");
		if(thumb)
			thumb.val("");
	});
}
/**
 * 保存数据
 */
function saveData(url,formid,toshow){
	var data = $('#'+formid).serialize();
	var errors="";
	var description="";
	if(formid == 'stepForm'){
		var descImg = new Array();
		$("#desc_img_box img").each(function(key,imgs){
			if(this.src.length > 0){
				descImg[key] = this.src ;
			}
		});
		data = data + '&descimg='+descImg;
		var content="";
		$("input[name^=content_title_").each(function(tk,te){
			var content_content="";
			$(this).parent().parent().parent().find('textarea[name^=content_step_]').each(function(k,e){
				var content_img="";
				$("#"+this.name+"_img_box img").each(function(key,imgs){
					if(this.src.length > 0){
						content_img += this.src+"[img]";
					}else{
						content_img +="";
					}
				});
				content_content +=encodeURIComponent(e.value)+"[imgages]"+content_img+"=@-=-=-=";
			});
			content += encodeURIComponent(te.value)+"[steps]"+content_content+"[title@step]";
		})
		data = data +'&content='+content;
	}
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({
				title: '系统提示',
                content: errors
            });
        },
		success: function(data){
			if(data.status == 'success'){
				if(toshow.length>0){
                    alert('333');
				}else if(data.redirectUrl.length > 0){
					layer.alert(data.msg, function(result) {
	                    location.href= data.redirectUrl;
		            });
				}else{
					location.href='/biz/cominfo-index';
				}
			}else{
				layer.open({
					title: '系统提示',
                    content: data.msg
                });
			}

		},
	});
}
/**
*
* @param url  默认 category
* @param pid
* @param ids
*/
function getChilds(url,pid,ids){
	$.ajax({
		'url':'/'+url,
		'type':'GET',
		'data':'parentid='+pid,
		success: function(data){
   		if(data.status == 'success'){
       		var result = data.data;
       		var options ="";
       		if(result.length > 0){
           		$.each(result,function(k,e){
           			options +='<option value="'+e.cat_id+'">'+e.cat_name+'</option>';
               	});
           		if(ids == 'parent'){
               		var html = '<select name="child_1" class="form-control" id="child_1" onchange=\'getChilds("'+url+'",this.value,"child_1")\'>'+
               				'<option value="0">请选择分类</option>';
						html += options;
               		html += '</select>';
       				$("#child_1").html(html);
               	}else if (ids == 'child_1'){
               		var html = '<select name="child_2" class="form-control" id="child_2" onchange=\'getChilds("'+url+'",this.value,"child_1")\'>'+
       				'<option value="0">请选择分类</option>';
               		html += options;
               		html += '</select>';
       				$("#child_2").html(html);
                   }else if (ids == 'child_2'){
               		var html = '<select name="child_3" class="form-control" id="child_3"">'+'<option value="0">请选择分类</option>';
               		html += options;
               		html += '</select>';
       				$("#child_3").html(html);
                   }
       		}
       		else
       		{
       			if(ids == 'parent'){
       				$("#child_1").html("");
       				$("#child_2").html("");
       				$("#child_3").html("");
               	}else if (ids == 'child'){
       				$("#child_2").html("");
       				$("#child_3").html("");
                   }else if (ids == 'subchild'){
       				$("#child_3").html("");
                   }
       		}
   		}else{

   		}
   	},
	});
}
/**
 * 青苜社区 选择板块
 */
function toCheckPlate(id,name){
	$("input[name=plate_first_id]").val(id);
	$("#check_plate").text(name);
	$.ajax({
		'url':'/bbsplates',
		'type':'GET',
		'data':'parentid='+id,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({
				title: '系统提示',
                content: errors
            });
		},
		success: function(data){
			var html = "";
			if($("#child-plate").has('hide'))
				$("#child-plate").removeClass('hide');
			if(data.status == 'success'){
				$.each(data.data,function(k,v){
					if(k == 0){
						toChangePlate(v.id,v.title);
					}
					html += '<li><a href="javascript:void(0)" onclick="toChangePlate(\''+v.id+'\',\''+v.title+'\')">'+v.title+'</a></li>';
				});
				$("#child-menu").html(html);
			}else{
				html = '<li><a href="javascript:void(0)">没有更多的数据</a></li>';
				$("#child-menu").html(html);
			}
		},
	});
}
/**
 * 青苜社区 改变板块信息
 * @param id
 * @param name
 */
function toChangePlate(id,name)
{
	$("input[name=plate_child_id]").val(id);
	$("#change_plate").text(name);
}
/**
 * 投递简历
 * @param jobsid 职位id
 * @param resumeid 简历ID
 */
function deliveryResume(url,formid)
{
	var data = $('#'+formid).serialize();
	$.ajax({
		'url':url,
		'type':'POST',
		'data':data,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({
				title: '系统提示',
                content: errors
            });
		},
		success: function(data){
			if(data.status == 'success'){
				$("#goExam").html("<a href='javascript:void(0);'>已参与</a>");
				$("#goDelivery").html("<a href='javascript:void(0)'>已申请</a>");
				layer.msg(data.msg,{icon:1});
			}else{
				$("#goExam").find("a").html("重新考试");
				layer.msg(data.msg);
			}
		},
	});
}

/**
 * 图片移动
 */
function xweidrag(){
	$('.drag').draggable({
		  appendTo: 'body',
		  helper: 'clone'
	});
	$('.dropzone').droppable({
	  activeClass: 'active',
	  hoverClass: 'hover',
	  accept: ":not(.ui-sortable-helper)", // Reject clones generated by sortable
	  drop: function (e, ui) {
	    var $el = $('<div class="drop-item"><img src="' + ui.draggable[0].childNodes[0].src + '" width="100"></div>');
	    $el.append($('<a class="small-pic-del"><i class="icon-remove"></i></a>').click(function () { $(this).parent().detach(); }));
	    ui.draggable.remove();
	    $(this).find("span").remove();
	    $(this).append($el);
	  }
	}).sortable({
	  items: '.drop-item',
	  sort: function() {
	    // gets added unintentionally by droppable interacting with sortable
	    // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
	    $( this ).removeClass( "active" );
	  }
	});
}
function goBackStep(){
	$('#qiehuan').css('display','block');
	$('#big_pic').css('display','none');
}
function goBigStep(){
	$('#qiehuan').css('display','none');
	$('#big_pic').css('display','block');
}
function toStudy(id,url,teachesid,token,contentid){
	$.ajax({
		'url':url,
		'type':'POST',
		'data':'teachesid='+teachesid+'&contentid='+contentid+'&_token='+token,
		error: function(data) {
			var response = data.responseJSON;
			$.each(response,function(k,v){
				errors +="<div>"+v+"</div>";
			})
			layer.open({
				title: '系统提示',
                content: errors
            });
		},
		success: function(data){
			if(data.status == 'success'){
				layer.msg( data.msg,{time: 1000}, function(){
					window.location.href=data.redirectUrl;
				});
			}else if(data.status == '2008'){
				ShowLogin('MyDiv','fade');
			}else{
				layer.msg(data.msg);
			}
		},
	});
}
/**
 * 消息详情
 */
function message(url,token)
{
    $.ajax({
        type:'post',
        cache:'false',
        url:url,
        data:'_token='+token,
        dataType:'json',
        error: function(data) {
            layer.open({title:'提示',content:'网络异常'});
        },
        success: function(data){
            if(data.status == 'success')
            {
                var result = data.data;
                var html = "";
                $.each(result.data,function(k,v){
                    html += '<div class="talk_time">'+v.created_at+'</div>';
                    if(v.user_id != result.uid){
                        html += '<div class="ml-10 fl">'
                            +'<img src="'+result.otherLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;">'
                            +'<i class="glyphicon glyphicon-triangle-left" style="color:rgb(246,246,246);top:3px;left: -2px"></i>'
                            +'<div class="talk_left_d word">'
                            +'	<span class="talk_left_s">'+v.message+'</span>'
                            +'</div>'
                            +'</div><div class="clearfix"></div>';
                    }else{
                        html += '<div class="mr-10 fr">'
                            +'<img src="'+result.selfLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;" class="fr">'
                            +'<i class="glyphicon glyphicon-triangle-right" style="color:rgb(246,246,246);top: 20px;left: 105px;"></i>'
                            +'<div class="talk_right_d word">'
                            +'	<span class="talk_right_s">'+v.message+'</span>'
                            +'</div>'
                            +'</div><div class="clearfix"></div>';
                    }
                });
                html +="<input type='hidden' name='rid' value='"+result.rid+"'><input type='hidden' name='id' value='"+result.id+"'>";
                $('#myModalLabel').html(result.recipientname);
                $('#messge_send').attr('onclick','sendMessage("/message/save","messageForm")');
                $('#message_content').html(html);
                $('#myMessageDetail').modal();
            }else{
                var result = data.data;
                var html = "";
                html +="<input type='hidden' name='rid' value='"+result.rid+"'><input type='hidden' name='id' value=''>";
                $('#myModalLabel').html(result.recipientname);
                $('#messge_send').attr('onclick','sendMessage("/message/save","messageForm")');
                $('#message_content').html(html);
                $('#myMessageDetail').modal();
            }
        }
    });
}
/**
 * 发送消息
 */
function sendMessage(url,formid)
{
    var data = $('#'+formid).serialize();
    $.ajax({
        'url':url,
        'type':'POST',
        'data':data,
        error: function(data) {
            layer.open({title:'提示',content:'网络异常'});
        },
        success: function(data){
            if(data.status == 'success'){
                var result = data.data;
                var html = '<div class="talk_time">'+result.created_at+'</div>';
                html += '<div class="mr-10 fr">'
                    +'<img src="'+result.selfLogo+'" width="50" height="50" style="border-radius: 25px;width: 50px; height: 50px;" class="fr">'
                    +'<i class="glyphicon glyphicon-triangle-right" style="color:rgb(246,246,246);top: 20px;left: 105px;"></i>'
                    +'<div class="talk_right_d word">'
                    +'	<span class="talk_right_s">'+result.message+'</span>'
                    +'</div>'
                    +'</div><div class="clearfix"></div>';

                $("#message_content").append(html);
                $("#msgContent").val('');
                $("input[name=id]").val(result.notifyid);
            }
            else
            {
                layer.open({title:'提示',content:data.msg});
            }
        }
    });
}
function reportStep(now,prev,url)
{
	if(url == "" || url == null)
	{
		changeReportStep(prev,now);
	}else{
		var data = $('#reportForm').serialize();
		if(($('input[name=verfy_code]').val() == null || $('input[name=verfy_code]').val() == '')
				&& ($('input[name=verfy_code_2]').val() == null || $('input[name=verfy_code_2]').val() == '')){
			layer.msg('请输入验证码！');return false;
		}
		$.ajax({
			'url':url,
			'type':'POST',
			'data':data,
			error: function(data) {
				var response = data.responseJSON;
				var errors='';
				$.each(response,function(k,v){
					errors +="<div>"+v+"</div>";
				})
	            layer.open({title:'提示',content:errors});
	        },
	        success: function(data){
	            if(data.status == 'success'){
	            	changeReportStep(prev,now);
	            }
	            else
	            {
	                layer.open({title:'提示',content:data.msg});
	            }
	        },
		});
	}
}
function changeReportStep(prevd,nowd)
{
	if($("#"+prevd).hasClass("hide")){
		$("#"+prevd).removeClass('hide');
		$("#"+prevd+"_btn").removeClass('hide');
	}
	if($("#"+prevd+"_ti_cursor").hasClass('hide')){
		$("#"+prevd+"_ti_cursor").removeClass('hide');
		$("#"+prevd+"_ti").addClass('hide');
	}else{
		$("#"+prevd+"_ti_cursor").addClass('hide');
		$("#"+prevd+"_ti").removeClass('hide')
	}
	$("#"+nowd).addClass('hide');
	$("#"+nowd+"_btn").addClass('hide');
	if($("#"+nowd+"_ti_cursor").hasClass('hide')){
		$("#"+nowd+"_ti_cursor").removeClass('hide');
		$("#"+nowd+"_ti").addClass('hide');
	}else{
		$("#"+nowd+"_ti_cursor").addClass('hide');
		$("#"+nowd+"_ti").removeClass('hide')
	}
}
function checkParam(islogin,formid)
{
	if(islogin == 0 || islogin == 'undefined' || islogin == null || islogin == '0'){
		layer.msg('请登录先。。。');
		ShowLogin('MyDiv','fade');
		return false;
	}else{
		$(formid).submit();
	}
}

//提示登录
function  messageTips()
{
//    layer.open({
//        title: '提示',
//        content: '请不要对自己私信！'
//    });
    layer.msg('请不要对自己私信！');
}
function getverify(formid,type)
{
	var phone = $('#'+formid+' input[name=username]').val();
	var token = $('#'+formid+' input[name=_token]').val();
	if(phone == '' || phone.length == 0){
		layer.msg('手机或邮箱不可为空！');
		return false;
	}
	$('#to_verify').attr('disabled','disabled');
	$.post('/sendmsg',{'phone':phone,'_token':token,'type':type},function(data){
		if(data.status == 'success'){
			layer.msg(data.msg);
			$('#jump_next').removeAttr("disabled");
		}else{
			layer.msg(data.msg);
			return false;
		}
	});
	return regCountDown(60);
}
function regCountDown(grap)
{
	var i= grap;
	var countDown=setInterval(function(){
		$('#counter').removeClass('hide');
		$('#to_verify').removeClass('selected');
		if(i>0){
			$('#counter').html(i+"s");
			$('#counter_cnt').html('重新获取验证码');
			i--;
		}else if(i == 0){
			clearInterval(countDown);
			$('#counter').addClass('hide');
			$('#to_verify').addClass('selected');
			$('#to_verify').removeAttr('disabled');
			i=grap;
		}
	},1000);
	return false;
}
function resetverify(formid)
{
	var phone = $('#'+formid+' input[name=username]').val();
	var token = $('#'+formid+' input[name=_token]').val();
	if(phone == '' || phone.length == 0){
		layer.msg('手机或邮箱不可为空！');
		return false;
	}
	$('#to_verify').attr('disabled','disabled');
	$.post('/sendmsg',{'phone':phone,'_token':token,'type':1},function(data){
		if(data.status == 'success'){
			layer.msg(data.msg);
		}else{
			layer.msg(data.msg);
		}
	});
	return resetCountDown(60);
	return false;
}
/**
 * 计时
 * @param grap
 * @returns {Boolean}
 */
function resetCountDown(grap)
{
	var i= grap;
	var countDown=setInterval(function(){
		$('#reset_counter').removeClass('hide');
		$('#to_verify_reset').removeClass('selected');
		if(i>0){
			$('#reset_counter').html(i+"s");
			$('#reset_counter_cnt').html('重新获取验证码');
			i--;
		}else if(i == 0){
			clearInterval(countDown);
			$('#reset_counter').addClass('hide');
			$('#to_verify_reset').addClass('selected');
			$('#to_verify_reset').removeAttr('disabled');
			i=grap;
		}
	},1000);
	return false;
}
/**
 * 参加考试
 * @param islogin
 * @returns {Boolean}
 */
function toExaminations(islogin){
	if(islogin == 0){
		loginTips();
		return false;
	}
	var html="<p>温馨提示：</p>"
			+"<p>	1、在规定时间内答题；</p>"
			+"<p>	2、请勿作弊，诚信为人之本；</p>"
			+"<p>	3、交卷后将会进行系统评分，请您耐心等待。</p>";
	layer.open({
		title: '系统提示',
		content: html,
		yes: function(index, layero){
            layer.close(index);
            $("#examination").modal({
		        keyboard: false
		    });
        }
	});

}
/***
function playHandler(){
	var data = $("#videoseeFrom").serialize();
	$.ajax({
        'url':'/video',
        'type':'POST',
        'data':data,
        error: function(data) {
            var response = data.responseJSON;
            $.each(response,function(k,v){
                errors +="<div>"+v+"</div>";
            })
            layer.open({
                title: '系统提示',
                content: errors
            });
        },
        success: function(data){
            if(data.status == 'success'){
            	CKobject.getObjectById('ckplayer_a1').newAddress(data.redirectUrl);
            	CKobject.getObjectById('ckplayer_a1').videoPlay();
            	removeListener();
            }else if(data.status == '2008'){
            	layer.msg(data.msg,{time: 1000});
            	CKobject.getObjectById('ckplayer_a1').videoPause();
            	return false;
            }else{
            	layer.msg(data.msg,{time: 1000});
            	CKobject.getObjectById('ckplayer_a1').videoPause();
            	return false;
            }

        }
    });
	CKobject.getObjectById('ckplayer_a1').videoPause();
	return false;
}
function removeListener(){//删除监听事件
	if(CKobject.getObjectById('ckplayer_a1').getType()){//说明使用html5播放器
		CKobject.getObjectById('ckplayer_a1').removeListener('play',playHandler);
	}
	else{
		CKobject.getObjectById('ckplayer_a1').removeListener('play','playHandler');
	}
}
function listener(){
	if(CKobject.getObjectById('ckplayer_a1').getType()){//说明使用html5播放器
		CKobject.getObjectById('ckplayer_a1').addListener('play',playHandler);
	}
	else{
		CKobject.getObjectById('ckplayer_a1').addListener('play','playHandler');
	}
}
*/
